package clinic.ms.controller;

import clinic.ms.entity.Admin;
import clinic.ms.service.AdminServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;



@Controller
public class Login {
    @Autowired
    AdminServiceImpl adminService = new AdminServiceImpl();
    Admin admin;

    @RequestMapping("/Login")
    @ResponseBody
    public ModelAndView Login()
    {
        return new ModelAndView("/Login");
    }


    @RequestMapping("/addPatient")
    @ResponseBody
    public ModelAndView addPatient()
    {
        return new ModelAndView("/addPatient");
    }


    @ResponseBody
    @PostMapping("/login")
    public ModelAndView login(@RequestParam("username") String username,@RequestParam("password") String password)
    {

        if(password.equals(adminService.queryAdByName(username).getPassword()))
        {
            admin = adminService.queryAdByName(username);
            System.out.println(admin);
            return new ModelAndView("/NewMenu");
        }
        else
        {
            return  new ModelAndView("/Login");
        }
    }
    public Admin getName()
    {
        return admin;
    }


}
